// 用户认证相关API
import { axiosInstance } from './request'

const authAPI = {
  // 用户登录（支持密码和验证码两种方式）
  login(data) {
    return axiosInstance({
      url: '/auth/login',
      method: 'post',
      data,
    })
  },
  // 忘记密码
  forgotPassword(data) {
    return axiosInstance({
      url: '/auth/forgot-password',
      method: 'post',
      data,
    })
  },
  // 用户注册
  register(data) {
    return axiosInstance({
      url: '/auth/register',
      method: 'post',
      data,
    })
  },
  // 获取用户信息
  getUserInfo() {
    return axiosInstance({
      url: '/auth/me',
      method: 'get',
    })
  },
  // 更新用户信息
  updateProfile(data) {
    return axiosInstance({
      url: '/auth/profile',
      method: 'put',
      data,
    })
  },
  // 登出
  logout() {
    return axiosInstance({
      url: '/auth/logout',
      method: 'post',
    })
  },
  // 刷新token
  refreshToken() {
    return axiosInstance({
      url: '/auth/refresh',
      method: 'post',
    })
  },
  // 修改密码
  changePassword(data) {
    return axiosInstance({
      url: '/auth/password',
      method: 'put',
      data,
    })
  },
  // 上传头像
  uploadAvatar(file) {
    const formData = new FormData()
    formData.append('avatar', file)
    
    return axiosInstance({
      url: '/auth/upload-avatar',
      method: 'post',
      data: formData,
      headers: {
        'Content-Type': 'multipart/form-data'
      }
    })
  },
  // 发送短信验证码
  sendSmsCode(data) {
    return axiosInstance({
      url: '/sms/send',
      method: 'post',
      data,
    })
  },
  // 验证短信验证码
  verifySmsCode(data) {
    return axiosInstance({
      url: '/sms/verify',
      method: 'post',
      data,
    })
  },
  // 实名认证
  verifyIdentity(data) {
    return axiosInstance({
      url: '/users/verify',
      method: 'post',
      data,
    })
  },
}

// 导出整个 API 对象
export default authAPI

// 也可以单独导出每个方法
export const { login, register, getUserInfo, updateProfile, logout, refreshToken, changePassword, forgotPassword, uploadAvatar, sendSmsCode, verifySmsCode, verifyIdentity, refreshBalance } = authAPI 